<template>
    <div id="login">
        <section id="filter" ref="sections" style="">
        </section>
        <section>
            <div class="section_login">
                <img class="img2" src="" />
                <input v-model="username" type="text" name="" id="" placeholder="User name">
                <input v-model="password" type="password" name="" id="" placeholder="password">
                <input type="password" name="" id="" placeholder="Again password">
                <input @click='regs' type="button" value="Register" style="margin-bottom:12px;color:#ececec">
                <div>
                    <router-link to="/login" tag="span">Direct Login</router-link>
                    <span>|</span>
                    <span>Forgot password?</span>
                </div>
                <p>Welcome to join us</p>
                <router-link to="/home" tag="p">Visitor identity browsing</router-link>
            </div>
        </section>
    </div>
</template>

<script>
export default {
    beforeRouteEnter(to, from, next) {
        next(vm => {
            if (to.path == '/reg') {
                vm.$store.dispatch('hidefooter')
                vm.$store.dispatch('hideheader')
            } else {
                vm.$store.dispatch('showfooter')
                vm.$store.dispatch('showheader')
            }
        })
    },
    data() {
        return {
            username: '',
            password: '',
        }
    },
    methods: {
        regs() {
            var that = this;
            console.log(that.username);
            console.log(that.password);
            var formdata = new FormData();
            formdata.append('username', that.username)
            formdata.append('password', that.password)
            that.$http({
                url: '/reg',
                method: 'post',
                data: formdata
            }).then((res) => {
                console.log(res.data);
                if (res.data == 'Success') {
                    mui.toast('注册成功', { duration: '1000', type: 'div' })
                    setTimeout(function() {
                        that.$router.push('/login');
                    }, 1100);
                } else {
                    mui.toast('该账号已注册', { duration: 'long', type: 'div' })
                }
            }).catch((err) => {
                console.log(err);
            })
        }
    },
}
</script>
<style scoped>
section#filter {
    background-image: radial-gradient(circle at 106% -169%, #7900de, #9a61b4, #f750e3);
    -moz-filter: blur(1px);
    -webkit-filter: blur(1px);
    -o-filter: blur(1px);
    -ms-filter: blur(1px);
    filter: blur(1px);
    z-index: -1;
}

section {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
}

section:nth-child(2) {
    display: flex;
    justify-content: center;
}

section img {
    border-radius: 100%;
    width: 105px;
    height: 105px;
    margin-top: -90px;
    margin-bottom: 25px;
}

.section_login {
    text-align: center;
    margin: 130px auto 0px;
}

.section_login input {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 30px;
    width: 90%;
    margin-top: 5px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 14px;
    color: #333;
    height: 35px;
}

.section_login input::placeholder {
    color: #cacaca;
}

.section_login>div {
    display: flex;
    color: #555;
}

.section_login>div span:nth-child(1) {
    flex: 2;
}

.section_login>div span:nth-child(1) {
    text-align: right;
}

.section_login>div span:nth-child(2) {
    width: 55px;
}

.section_login>div span:nth-child(3) {
    flex: 3;
    text-align: left;
}

.section_login p {
    text-align: center;
    color: #333;
    margin-top: 15px;
}
</style>


